/*!
 * \file cics_eci.h
 *
 * \brief ECI调用
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.
 *
 * \version 1.0
 * \author songbb
 * \date 2015/10/07
 *
 */

#ifndef __CICS_ECI_H_
#define __CICS_ECI_H_

/*! @brief ECI调用的CallType类型 */
typedef enum __em_eci_call_type {
    APM_CICS_ECI_UNKNOWN,                   //!< 对应UNKNOWN
    APM_CICS_ECI_SYNC,                      //!< 对应SYNC
    APM_CICS_ECI_ASYNC,                     //!< 对应ASYNC
    APM_CICS_ECI_GET_REPLY,                 //!< 对应GET_REPLY
    APM_CICS_ECI_GET_REPLY_WAIT,            //!< 对应GET_REPLY_WAIT
    APM_CICS_ECI_GET_SPECIFIC_REPLY,        //!< 对应GET_SPECIFIC_REPLY
    APM_CICS_ECI_GET_SPECIFIC_REPLY_WAIT,   //!< 对应GET_SPECIFIC_REPLY_WAIT
    APM_CICS_ECI_STATE_SYNC,                //!< 对应STATE_SYNC
    APM_CICS_ECI_STATE_ASYNC,               //!< 对应STATE_ASYNC
    APM_CICS_CICS_ECILISTSYSTEMS,           //!< 对应CICS_ECILISTSYSTEMS
    APM_CICS_ECI_STATE_SYNC_JAVA,           //!< 对应STATE_SYNC_JAVA
    APM_CICS_ECI_STATE_ASYNC_JAVA,          //!< 对应STATE_ASYNC_JAVA
    APM_CICS_ECI_SYNC_TPN,                  //!< 对应SYNC_TPN
    APM_CICS_ECI_ASYNC_TPN                  //!< 对应ASYNC_TPN
} Cics_eci_call_type;

/*! @brief ECI调用的ExtendMode类型 */
typedef enum __em_eci_extend_mode {
    APM_CICS_ECI_NO_EXTEND,                 //!< 对应NO_EXTEND
    APM_CICS_ECI_EXTENDED,                  //!< 对应EXTENDED
    APM_CICS_ECI_COMMIT,                    //!< 对应COMMIT
    APM_CICS_ECI_CANCEL,                    //!< 对应CANCEL
    APM_CICS_ECI_BACKOUT,                   //!< 对应BACKOUT
    APM_CICS_ECI_STATE_IMMEDIATE,           //!< 对应STATE_IMMEDIATE
    APM_CICS_ECI_STATE_CHANGED,             //!< 对应STATE_CHANGED
    APM_CICS_ECI_STATE_CANCEL               //!< 对应STATE_CANCEL
} Cics_eci_extend_mode;


#define CICS_ECI_CALLTYPE2STR(x) ((x==APM_CICS_ECI_SYNC)?"ECI_SYNC": \
                                 ((x==APM_CICS_ECI_ASYNC)?"ECI_ASYNC": \
                                 ((x==APM_CICS_ECI_GET_REPLY)?"ECI_GET_REPLY": \
                                 ((x==APM_CICS_ECI_GET_REPLY_WAIT)?"ECI_GET_REPLY_WAIT": \
                                 ((x==APM_CICS_ECI_GET_SPECIFIC_REPLY)?"ECI_GET_SPECIFIC_REPLY": \
                                 ((x==APM_CICS_ECI_GET_SPECIFIC_REPLY_WAIT)?"ECI_GET_SPECIFIC_REPLY_WAIT": \
                                 ((x==APM_CICS_ECI_STATE_SYNC)?"ECI_STATE_SYNC": \
                                 ((x==APM_CICS_ECI_STATE_ASYNC)?"ECI_STATE_ASYNC": \
                                 ((x==APM_CICS_CICS_ECILISTSYSTEMS)?"CICS_EciListSystems": \
                                 ((x==APM_CICS_ECI_STATE_SYNC_JAVA)?"ECI_STATE_SYNC_JAVA": \
                                 ((x==APM_CICS_ECI_STATE_ASYNC_JAVA)?"ECI_STATE_ASYNC_JAVA": \
                                 ((x==APM_CICS_ECI_SYNC_TPN)?"ECI_SYNC_TPN": \
                                 ((x==APM_CICS_ECI_ASYNC_TPN)?"ECI_ASYNC_TPN":"ECI_UNKNOWN_CALL_TYPE")))))))))))))  //!< CallType返回值转字符串

#define CICS_ECI_RC2STR(x) ((x==0)?NULL: \
                           ((x==1)?"ECI_ERR_INVALID_DATA_LENGTH": \
                           ((x==2)?"ECI_ERR_INVALID_EXTEND_MODE": \
                           ((x==3)?"ECI_ERR_NO_CICS": \
                           ((x==4)?"ECI_ERR_CICS_DIED": \
                           ((x==5)?"ECI_ERR_REQUEST_TIMEOUT_OR_ERR_NO_REPLY": \
                           ((x==6)?"ECI_ERR_RESPONSE_TIMEOUT": \
                           ((x==7)?"ECI_ERR_TRANSACTION_ABEND": \
                           ((x==8)?"ERR_LUW_TOKEN": \
                           ((x==9)?"ECI_ERR_SYSTEM_ERROR": \
                           ((x==10)?"ECI_ERR_NULL_WIN_HANDLE": \
                           ((x==12)?"ECI_ERR_NULL_MESSAGE_ID": \
                           ((x==13)?"ECI_ERR_THREAD_CREATE_ERROR": \
                           ((x==14)?"ECI_ERR_INVALID_CALL_TYPE": \
                           ((x==15)?"ECI_ERR_ALREADY_ACTIVE": \
                           ((x==16)?"ECI_ERR_RESOURCE_SHORTAGE": \
                           ((x==17)?"ECI_ERR_NO_SESSIONS": \
                           ((x==18)?"ECI_ERR_NULL_SEM_HANDLE": \
                           ((x==19)?"ECI_ERR_INVALID_DATA_AREA": \
                           ((x==21)?"ECI_ERR_INVALID_VERSION": \
                           ((x==22)?"ECI_ERR_UNKNOWN_SERVER": \
                           ((x==23)?"ECI_ERR_CALL_FROM_CALLBACK": \
                           ((x==25)?"ECI_ERR_MORE_SYSTEMS": \
                           ((x==26)?"ECI_ERR_NO_SYSTEMS": \
                           ((x==27)?"ECI_ERR_SECURITY_ERROR": \
                           ((x==28)?"ECI_ERR_MAX_SYSTEMS": \
                           ((x==29)?"ECI_ERR_MAX_SESSIONS": \
                           ((x==30)?"ECI_ERR_ROLLEDBACK": \
                           ((x==31)?"ECI_ERR_XID_INVALID":"ECI_UNKNOWN_CICS_RC")))))))))))))))))))))))))))))    //!< RC返回值转字符串

#define CICS_ECI_RC22STR(x) ((x==0)?"ECI_ERR_NO_MSG_QUALS": \
                           ((x==1)?"ECI_ERR_MSG_QUAL_IN_USE":"ECI_UNKNOWN_CICS_RC"))    //!< RC2返回值转字符串

/*!
 * 解析ECI请求
 *
 * \param p_st_conn         (ct信息)
 * \param p_st_sess         (CICS的session信息)
 * \param p_st_cics_packet  (CICS数据包)
 * \param p_st_hash_report  (数据上报用)
 *
 * \return 0  失败\n
 *         1  成功
 *
 */
int cics_eci_req(Conntrack *p_st_conn
                , L7session_cics *p_st_sess
                , L7_cics_packet *p_st_cics_packet
                , Frhash_header *p_st_hash_report);

/*!
 * 解析ECI响应
 *
 * \param p_st_conn         (ct信息)
 * \param p_st_sess         (CICS的session信息)
 * \param p_st_cics_packet  (CICS数据包)
 * \param p_st_hash_report  (数据上报用)
 *
 * \return 0  失败\n
 *         1  成功
 *
 */
int cics_eci_resp(Conntrack *p_st_conn
                , L7session_cics *p_st_sess
                , L7_cics_packet *p_st_cics_packet
                , Frhash_header *p_st_hash_report);

#endif
